﻿$(function() {
	/**
	 * 设备开动情况
	 * */
    var dayline = echarts.init(document.getElementById('singlechart'));
    optionline = {
        tooltip : {
            trigger: 'axis',
            axisPointer: {
		        type: 'shadow'
		    }
        },
        backgroundColor:'#e0e0e0',
        grid: {
            top: '15%',
            left: '4%',
            right: '5%',
            bottom:'20%',
            containLabel: true
        },
        legend: {
        	top: '10',
	        data:['耗电量/满载率']
	    },
        xAxis:  {
            type: 'category',
            boundaryGap: [1, 1],
            data: [],//['1','2','3','4','5','6'],
//            name:'时',
            splitLine:{
            	show:false
            }
        },
        yAxis: {
            type: 'value',
            name:'率',
            axisLabel:{
	    		 formatter: '{value}'
	    	 },
            splitLine:{
            	show:false
            }
        },
	    series: [{
            name:'耗电量/满载率',
            type:'line',
            data:[],//[0.8,0.9,0.84,0.7,0.8,0.91],
            markPoint: {
               data: [
                  {type: 'max', name: '最高值'},
                  {type: 'min', name: '最低值'}
		         ]
		     }
        }]
    };
    dayline.setOption(optionline);
    
    var equId=0;
    var	startMonth=1;
    var	endMonth=1;
    var year=moment().year();
    
    /**
     * slider滑动事件
     * */
    $('#ss').slider({
    	range: true,
    	max:12,
		tipFormatter: function(value){    
        	return "第"+value+"月";
        },
        onComplete:function(value){//滑块值改变时触发
	       	startMonth=value[0];
	       	endMonth=value[1];
	       	getData();
       }
    });
    
    /**
     * 初始化
     * */
    var vm = new Vue({
	    el: '#itemData',
	    data:{item:[]}
	}); 

    var weeks=[1,moment().month()+1];
    $('#ss').slider('setValues',weeks);
    var arr=$('#ss').slider('getValues');
    startMonth=arr[0];
    endMonth=arr[1];
    getData();
    function getData(){
    	console.log("capacity---month");
    	$.post(basePath+"/energy/agingData/month.json",{"equId":equId,year:year,start:startMonth,end:endMonth},function(res){
    		vm.$set('item',res);
//    		if(res.success){
    		dayline.setOption({
		        xAxis: {
		            data: res.months
		        },
		        series: [{
		        	name:'耗电量/满载率',
		            data: res.rateDatas
		        }]
			});
//    		}else{
//    			alert("日期无效");
//    		}	
    	});
    }


    /**
     * 自定义时间按钮的点击事件
     * */
    $("#defineTime").click(function (){
		 var mePanel = $('#defineTimeWin');
	   	 mePanel.dialog('open');
	 });
	$('#defineTimeWin').dialog({
		title:'自定义时间',
		width:400,
		height:150,
		iconCls:'icon-add',
		closed: true,
		modal: true,
		inline:true,
		buttons:[{
			text:'确定',
			iconCls:'icon-add-new',
			handler:function(){
					var st=$("input[name='startTime']").val();
					year=st;
					getData();
					$('#defineTimeWin').dialog('close');

			}
		},{
			text:'取消',
			iconCls:'icon-redo',
			handler:function(){
				$('#defineTimeWin').dialog('close');
			}
		}],
		onClose: function() {
			$('#defineTimeform').form('reset');
		}
	});
	

	/**
	  * 切换设备的点击事件
	  * */
	var mePanel = $('#switchEquip');
	$("#linetree").tree({
		onClick: function(node) {
			if (node.url) {
				var lineGrid = $('#lines_data');
				lineGrid.datagrid('load',{
					lineId:node.id
				});
				lineGrid.datagrid('getPanel').panel('setTitle',node.text);
			}
		}
	});
	$('#lines_data').datagrid({
		//双击设备时，根据选中设备刷新
		onDblClickRow: function(rowIndex, rowData){
			equId=rowData.id;
			var arr=$('#ss').slider('getValues');
		    startMonth=arr[0];
		    endMonth=arr[1];
		    getData();
		    mePanel.dialog('close');
		}
	});
 $("#switchEquipOK").click(function(){
 	var row = $('#lines_data').datagrid('getSelected');
 	if(row){
 		equId=row.id;
 		var arr=$('#ss').slider('getValues');
 	    startMonth=arr[0];
 	    endMonth=arr[1];
 	    getData();
		$('#switchEquip').dialog('close');
 	}else{
 		$.messager.alert({showSpeed:100,title:'消息提示',msg:'请选择一条设备记录!',timeout:3000});
 	}
 });

    

    
});